const {addmember,removemember,updatemember,getdata} = require('../models/model');

const addMember =async function(req,res,next){
    let data = req.body;
    //res.send(data);
    let result = await addmember(data);
    let {name} = result;
    console.log(name);
    if(result){
        res.send({status:1,state:true,msg:'新增成功',data:result})
    }else{
        res.send({status:0,state:false,msg:'新增失败'})
    }
}
const removeMember =async function(req,res,next){
    let data = req.body;
    //res.send(data);
    let result = await removemember(data);
    //res.send(result);
    if(result.n){
        res.send({status:1,state:true,msg:'删除成功',data:result}) 
    }else{
        res.send({status:0,state:false,msg:'删除失败'})
    }
}
const updateMember =async function(req,res,next){
    let data = req.body;
    res.send(data);
    let result = await updatemember(data[0],data[1]);

}
const getData =async function(req,res,next){
    let data = req.query;
    //res.send(data);
    let result = await getdata(data);
    //res.send(result)
    if(result.length){
        res.send({status:1,state:true,msg:'获取成功',data:result})
    }else{
        res.send({status:0,state:false,msg:'获取失败'})
    }
}




module.exports={
    addMember,
    removeMember,
    updateMember,
    getData
}